home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: 10 Mar 1996 11:03:25 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4huctt$arv@sparcserver.lrz-muenchen.de>
- References: <4htonk$350@news.hklink.net>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- alex@station.net (Alex Chu) writes:
-
-
- >Hi everybody,
-
- >I have a question for the following snip C program.
-
- >typedef struct item {
- > int val;
- > struct item *next;
- >} ITEM, *PITEM;
-
- >main()
- >{
- > PITEM head, current;
- > head=(PITEM) malloc(sizeof(ITEM));
- > ^^^^^^^
- > head->val=1;
- >}
-
- >I want to know why need to use the type casting PITEM in front of the
- >malloc ? Please help!
-
- Simple answer: You don't have to use that cast, and you should _not_ use
- it, because all you can do with that cast is _hide_ an error.
-
- OTOH, if you are using a C++ compiler to translate C programs, the cast
- is needed, but malloc() is obsolete.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-
-